/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fserv.control;

import fserv.entities.Command;
import fserv.entities.Reply;
import fserv.model.ServerData;
import fserv.ni.CtrlToNI;

/**
 *
 * @author arthur
 */
public class CommandRunner extends Thread {

  private Command cmd;
  private ServerData datas;
  CtrlToNI ni;

  public CommandRunner(CtrlToNI ni, Command cmd) {
    this.cmd = cmd;
    datas = ServerData.getInstance();
    this.ni = ni;
  }

  @Override
  public void run() {
    Reply rep = null;
    if(cmd.getMessage().equals("ls")) {
      rep = new Reply(datas.list());
    } else {
      rep = new Reply("Invalid command : "+cmd.getMessage());
    }

    ni.send(rep, cmd.getSourceAddr(), cmd.getSourcePort());
  }

  
}
